<template>
  <div>
    <table width="100%" bgcolor="#cccccc" cellpadding="1" cellspacing="1">
      <tr>
        <td valign="top" bgcolor="white">
          <div id="WebOCX">
            <object
              id="WebOffice"
              classid="clsid:FF09E4FA-BFAA-486E-ACB4-86EB0AE875D5"
              codebase="http://www.officectrl.com/weboffice/WebOffice.ocx#Version=2018,1,6,2"
              width="100%"
              height="600"
            >
              <param name="BorderStyle" value="1">
              <param name="Menubar" value="0">
              <param name="Titlebar" value="1">
              <param name="Toolbars" value="1">
            </object>
          </div>
        </td>
      </tr>
    </table>
  </div>
</template>
<script>
import * as WebCtrl from '@/assets/js/WebOffice.js' // 引用WebOffice插件库，注意路径
export default {
  props: {
    options: {
      // 插件配置
      type: Object,
      default: function() {
        return {
          Titlebar: false, // 标题隐藏
          IsNotCopy: false, // 不能复制，true不能复制，false可以复制
          Menubar: false, // 插件菜单栏是否显示
          Toolbars: false // 插件工具栏是否显示
        }
      }
    }
  },
  data() {
    return {
      filePath: this.$store.getters.courseWordPath || '', // 要打开的文件路径
      configs: {
        Titlebar: false,
        IsNotCopy: false,
        Menubar: false,
        Toolbars: false
      }
    }
  },
  created() {
    console.log(this.$store.getters)
  },
  mounted: function() {
    WebCtrl.LoadCtrl(WebOCX)
    if (document.getElementById('WebOffice')) {
      document.getElementById('WebOffice').UserName = '贵州鼎慧大数据科技有限公司'
      WebOffice.Titlebar = this.options.Titlebar
      WebOffice.IsNotCopy = this.options.IsNotCopy
      WebOffice.Menubar = this.options.Menubar
      WebOffice.Toolbars = this.options.Toolbars
      if (this.filePath !== '') {
        this.WebOfficeOpen()
      }
    }
  },
  methods: {
    WebOfficeOpen() {
      WebOffice.Open(this.filePath, 'Word.Document')
      // WebOffice.Open(this.filePath, true, 'Word.Document')
    },
    NoCopyIt: function(e) {
      WebCtrl.isNotCopy(e)
    },
    WebSignature: function(e) {
      var strpic
      if (e == 1) strpic = '001.gif'
      if (e == 2) strpic = '002.gif'
      if (e == 3) strpic = '003.gif'
      WebCtrl.WebSignature('http://www.officectrl.com/weboffice/images/' + strpic)
    },
    WebSave: function() {
      WebOffice.Save('http://www.officectrl.com/officecs/uploadedit.aspx?oper=edit&flsid=4167975720113410419&flag=1') // uploadedit.aspx是表单一个文件上传的后二进制接收器
    },
    WebHttpSave: function() {
      WebOffice.HttpInit()
      WebOffice.HttpAddPostString('filename', '4167975720113410419.doc')
      WebOffice.HttpAddPostCurrFile('docfile', '')
      // postsave.aspx是表单一个文件上传的后二进制接收器
      var strResults = WebOffice.HttpPost('http://www.officectrl.com/officecs/postsave.aspx')
      if (strResults === 'ok') {
        alert('保存成功！')
      }
    },
    WebDocReload: function() {
      location.reload()
    }
  }
}
</script>

<style lang="scss" scoped></style>
